﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Xml.Linq;
using Microsoft.SharePoint;
using System.Text.RegularExpressions;

namespace LizardSoft.Common.FlexibleStructureDeployment
{
    public static partial class StructureHelper
    {
        private static void AddOrUpdateList(SPWeb web, ListProcessingInfo listProcessingInfo)
        {
            SPList list = null;
            try { list = GetSPListFromFolderUrl(web, listProcessingInfo.ListFolderUrl); }
            catch { /* ok: список еще не существует */ }

            try
            {
                if (list == null)
                {
                    // создаем список
                    Guid listGuid = web.Lists.Add(listProcessingInfo.ListInternalName, listProcessingInfo.ListDescription, listProcessingInfo.TemplateType);
                    list = web.Lists[listGuid];
                }
                list.Title = listProcessingInfo.ListTitle;
                list.Description = listProcessingInfo.ListDescription;
                list.OnQuickLaunch = listProcessingInfo.ShowOnQuickLaunch;
                list.Hidden = listProcessingInfo.Hidden;
                list.Update();
            }
            catch (Exception ex)
            {
                string message = String.Format(
                    "Ошибка в методе AddOrUpdateListIfNeeded для списка {0}: {1}",
                    listProcessingInfo.ListInternalName,
                    ex.Message);
                throw new Exception(message, ex);
            }
        }
    }
}
